<?php

namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;

class DealBuyRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'deal_id' => 'required',
            'total_amount' => 'required|integer|min:1',
            'total_price' => 'required|numeric|min:0.01',
            'pay_type' => 'required',
        ];
        if($this->pay_type == 2){
            $rules['security'] = 'required';
        }
        return $rules;
    }

    public function messages()
    {
        $messages = [
            'deal_id.required' => '缺少参数deal_id',
            'total_amount.required' => '请输入购买数量',
            'total_amount.integer' => '购买数量必须为整数',
            'total_amount.min' => '购买数量最少1个',
            'total_price.required' => '请输入总金额',
            'total_price.numeric' => '总金额必须为数字',
            'total_price.min' => '金额有误',
            'pay_type.required' => '请选择付款方式',
        ];
        if($this->pay_type == 2){
            $messages['security.required'] = '请输入交易密码';
        }
        return $messages;
    }

}
